home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MainFunctions.c
-
- Contains:
-
- Written by:
-
- Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 8/2/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
- #ifndef __MAINFUNC__
- #include "MainFunctions.h"
- #endif
-
- extern SpeechChannel theSpeechChan;
- extern Boolean gDone;
-
- /*
- This is a dispatcher for dealing with what the user said. Add your functions to the switch
- statement, add an entry in the 'LANG' resource, and it should "just work".
- */
- OSErr ParseRefCon (SpeechInfoPtr theSpeechInfo, CommandPtr theCommand)
- {
- LanguageModelListPtr language;
- long type = 0;
- OSErr theErr = noErr;
- short word = 0;
- Boolean done = false,
- found = false;
-
- type = theCommand->type;
- word = theCommand->ID;
-
- PlaySndCommand (8192); /* Play the conformation tones */
-
- switch (type) {
- case 'LANG':
- language = theSpeechInfo->languages;
- while (done == false) {
- if (language->resID != word) {
- if (language->nextLanguage != nil) {
- language = language->nextLanguage;
- }
- else {
- done = true;
- found = false;
- }
- }
- else {
- done = true;
- found = true;
- }
- }
- if (found == true) {
- theErr = SRSetLanguageModel (theSpeechInfo->theRecognizer, language->theLanguage);
- }
- break;
- case 'chan':
- theErr = ChannelCommand (word);
- break;
- case 'lght':
- theErr = LightCommand (word);
- break;
- case 'scpt':
- theErr = ScriptCommand (word);
- break;
- case 'call':
- theErr = PhoneCommand (word);
- break;
- case 'game':
- theErr = GameCommand (word);
- break;
- case 'stro':
- theErr = StereoCommand (word);
- break;
- case 'tv ':
- theErr = TVCommand (word);
- break;
- case 'vcr ':
- theErr = VCRCommand (word);
- break;
- case 'ldsk':
- theErr = LaserdiskCommand (word);
- break;
- case 'vol ':
- theErr = VolumeCommand (word);
- break;
- case 'snd ':
- theErr = PlaySndCommand (word);
- break;
- case 'quit':
- theErr = QuitCommand (word);
- break;
- }
-
- return theErr;
- }
-
- OSErr ChannelCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- case 0:
- break;
- case 1:
- break;
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr LightCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- case 255:
- break;
- case 25:
- break;
- case 0:
- break;
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr ScriptCommand (long commandNumber)
- {
- ComponentInstance cmptInstance = 0;
- AEDesc desc = {0, nil};
- OSAID scriptID = 0,
- resultingOSAID = 0;
- OSErr theErr = noErr;
-
- cmptInstance = OpenDefaultComponent (kOSAComponentType, 'scpt');
- if (cmptInstance == nil)
- DebugStr ("\pOpenDefaultComponent failed, do you have AppleScript installed?");
- desc.descriptorType = 'scpt';
-
- desc.dataHandle = Get1Resource ('scpt', commandNumber);
- theErr = ResError ();
- if (desc.dataHandle == nil || theErr != noErr)
- DebugStr ("\pGet1Resource failed");
-
- theErr = OSALoad (cmptInstance, &desc, kOSAModeNull, &scriptID);
- if (theErr != noErr)
- DebugStr ("\pOSALoad failed");
-
- ReleaseResource (desc.dataHandle);
- theErr = OSAExecute (cmptInstance, scriptID, kOSANullScript, kOSAModeNull, &resultingOSAID);
- if (theErr != noErr)
- DebugStr ("\pOSAExecute failed");
-
- theErr = OSADispose (cmptInstance, scriptID);
- if (theErr != noErr)
- DebugStr ("\pOSADispose failed");
-
- theErr = CloseComponent (cmptInstance);
- if (theErr != noErr)
- DebugStr ("\pCloseComponent failed");
-
- return theErr;
- }
-
- OSErr PhoneCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr GameCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr StereoCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- case 0:
- break;
- case 1:
- break;
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr TVCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- case 0:
- break;
- case 1:
- break;
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr LaserdiskCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr VCRCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- break;
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr VolumeCommand (long commandNumber)
- {
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- default:
- ;
- }
-
- return theErr;
- }
-
- OSErr PlaySndCommand (long commandNumber)
- {
- Handle theSound = nil;
- OSErr theErr = noErr;
-
- switch (commandNumber) {
- default:
- theSound = GetResource ('snd ', commandNumber);
- theErr = ResError ();
- HLock (theSound);
- if (theSound != nil && theErr == noErr) {
- SndPlay (nil, (SndListHandle)theSound, false);
- HUnlock (theSound);
- ReleaseResource (theSound);
- }
- }
-
- return theErr;
- }
-
- OSErr QuitCommand (long commandNumber)
- {
- #pragma unused (commandNumber)
-
- Ptr goodbye = "You're welcome, good bye.";
- short goodbyeLen = 25;
- OSErr theErr = noErr;
-
- theErr = SpeakBuffer (theSpeechChan, (char *)goodbye, goodbyeLen, 0);
- if (theErr != noErr) {
- DebugStr ("\pSpeakBuffer failed");
- }
-
- gDone = true;
-
- return theErr;
- }
-